<template>
  <div class="ind-header" style="background: #ad6e3f">
    <div class="top">
      <router-link to="/">
        <img src="../assets/logo_4.png" alt="" />
      </router-link>
      <div class="top_02">
        <div>
          <router-link to="/">首 页</router-link>
        </div>
        <div>
          <router-link to="/wikipedia">宠物百科</router-link>
        </div>
        <div>
          <router-link to="/PetMedical">宠物医疗</router-link>
        </div>
        <div>
          <router-link to="/store">宠物商城</router-link>
        </div>
        <div>
          <a href="">客户服务</a>
        </div>
      </div>
      <div v-if="$store.state.loginUser">
        <span class="loginning"
          >欢迎，<router-link to="/center">{{
            $store.state.loginUser
          }}</router-link></span
        >&nbsp;&nbsp;
        <button @click="quitLogin">退出</button>
      </div>
      <div v-else>
        <button @click="toLogin" v-show="!$route.meta.hideLogin">登录</button>
        <button @click="$router.push('/register')">注册</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      path: this.$route.path,
    };
  },
  methods: {
    quitLogin() {
      this.$store.commit("quitLogin");
      this.$message({
        type: "success",
        message: "退出成功",
      });
      this.$router.push("/");
    },
    toLogin() {
      sessionStorage["loginBack"] = this.$route.fullPath;
      this.$router.push("/login");
    },
  },
  watch: {
    path: function (to, from) {
      console.log("to", to);
      console.log("from", from);
    },
  },
};
</script>

<style lang="scss" scoped>
.top {
  margin: 0 auto;
  width: 1440px;
  height: 100px;
  display: flex;
  justify-content: space-between;
  text-align: center;
  position: relative;
  z-index: 8;
  > a img {
    margin: 9px 0 14px 50px;
    width: 230px;
  }
  .top_02 > div {
    color: #101010;
    margin: 43px 0 37px;
    display: inline-block;
    > a {
      color: white;
      text-decoration: none;
      font-size: 23px;
    }
  }
  .top_02 > div:nth-child(n + 2) {
    margin-left: 57px;
  }
  button {
    width: 78px;
    height: 37px;
    background-color: #fc9ab2;
    border-radius: 10px;
    border: none;
    font-size: 14px;
    line-height: 20px;
    color: white;
    margin: 35px 39px 28px 0;
  }
  // 过渡样式
  button:hover {
    color: red;
  }
  .loginning {
    line-height: 100px;
    color: white;
    user-select: none;
    > a {
      color: white;
    }
    > a:hover {
      color: #fc9ab2;
      border-bottom: 1px solid #fc9ab2;
      cursor: pointer;
    }
  }
}
</style>
